/*
 * GLColor.cpp
 *
 *  Created on: 01-12-2010
 *      Author: Przemek
 */

#include "utils/GLColor.hpp"
#include "utils/RangedValue.hpp"
#include "pch.hpp"

const GLColor GLColor::WHITE(1.0f, 1.0f, 1.0f);
const GLColor GLColor::BLACK(0.0f, 0.0f, 0.0f);
const GLColor GLColor::RED(1.0f, 0.0f, 0.0f);
const GLColor GLColor::GREEN(0.0f, 1.0f, 0.0f);
const GLColor GLColor::BLUE(0.0f, 0.0f, 1.0f);

const Range<float> GLColor::ZERO_ONE_RANGE(0.0f, 1.0f);

GLColor::GLColor(float r, float g, float b) :
	r(ZERO_ONE_RANGE, r), g(ZERO_ONE_RANGE, g), b(ZERO_ONE_RANGE, b)
{
}

GLColor::GLColor(const GLColor& other) :
	r(other.r), g(other.g), b(other.b)
{
}

GLColor& GLColor::operator=(const GLColor& other)
{
	if(this != &other)
	{
		r = other.r;
		g = other.g;
		b = other.b;
	}

	return *this;
}

void GLColor::set(int r, int g, int b)
{
	this->r.setValue(r / 255.0f);
	this->g.setValue(g / 255.0f);
	this->b.setValue(b / 255.0f);
}

void GLColor::setGLState() const
{
	glColor3f(r.getValue(), g.getValue(), b.getValue());
}

void GLColor::setGLState(float alpha) const
{
	glColor4f(r.getValue(), g.getValue(), b.getValue(), alpha);
}

GLColor GLColor::lighten(float amount) const
{
	return GLColor(r.getValue() + amount, g.getValue() + amount, b.getValue() + amount);
}

GLColor GLColor::darken(float amount) const
{
	return lighten(-amount);
}
